package com.example.springboot.test;

import com.example.springboot.request.EbookQueryRequest;
import com.example.springboot.request.EbookSaveRequest;
import com.example.springboot.response.CommonResponse;
import com.example.springboot.response.EbookQueryResponse;
import com.example.springboot.response.PageResponse;
import com.example.springboot.service.ServiceEbook;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;


@RestController//表示访问这个地址时要返回一个字符串
public class EbookController {

    //查询
    @Resource
    private ServiceEbook serviceEbook;
    @GetMapping("/Ebook/service")
    public CommonResponse list(@Valid EbookQueryRequest ebookQueryRequest){
        CommonResponse<PageResponse<EbookQueryResponse>> response=new CommonResponse<>();
       PageResponse<EbookQueryResponse> list= serviceEbook.list(ebookQueryRequest);
        response.setContent(list);
        return response;
    }

    //保存
    @PostMapping("/Ebook/save")
    public CommonResponse save(@Valid @RequestBody EbookSaveRequest ebookQueryRequest){
        CommonResponse response=new CommonResponse<>();
        serviceEbook.save(ebookQueryRequest);
        return response;
    }

    //删除
    @DeleteMapping("/Ebook/delete/{id}")
    public CommonResponse delete(@PathVariable Long id){
        CommonResponse response=new CommonResponse<>();
        serviceEbook.delete(id);
        return response;
    }
}
